using System.Linq;
using NodeCanvas.Variables;
using UnityEngine;

namespace NodeCanvas.Actions
{
	[Category("Physics")]
	[AgentType(typeof(Transform))]
	[Description("Get hit info for ALL objects in the linecast, in Lists")]
	public class GetLinecastInfo2DAll : ActionTask
	{
		[RequiredField]
		public BBGameObject target;

		public LayerMask mask = -1;

		[BlackboardOnly]
		public BBGameObjectList saveHitGameObjectsAs;

		[BlackboardOnly]
		public BBFloatList saveDistancesAs;

		[BlackboardOnly]
		public BBVectorList savePointsAs;

		[BlackboardOnly]
		public BBVectorList saveNormalsAs;

		protected override void OnExecute()
		{
			RaycastHit2D[] array = Physics2D.LinecastAll(base.agent.transform.position, target.value.transform.position, mask);
			if (array.Length > 0)
			{
				saveHitGameObjectsAs.value = array.Select((RaycastHit2D h) => h.collider.gameObject).ToList();
				saveDistancesAs.value = array.Select((RaycastHit2D h) => h.fraction).ToList();
				savePointsAs.value = array.Select((RaycastHit2D h) => h.point).Cast<Vector3>().ToList();
				saveNormalsAs.value = array.Select((RaycastHit2D h) => h.normal).Cast<Vector3>().ToList();
				EndAction(true);
			}
			else
			{
				EndAction(false);
			}
		}

		protected override void OnGizmosSelected()
		{
			if ((bool)base.agent && (bool)target.value)
			{
				Gizmos.DrawLine(base.agent.transform.position, target.value.transform.position);
			}
		}
	}
}
